package com.example.spring.framework.aop.aspect;

import com.example.spring.framework.aop.intercept.MethodInvocation;
import com.example.spring.framework.aop.intercept.MethodInterceptor;

import java.lang.reflect.Method;

/**
 * @Classname AfterReunrningAdviceInterceptor
 * @Date 2019/4/23 0:00
 * @Author admin
 * @Description TODO
 */
public class AfterReunrningJAdviceInterceptor extends AbstractAspectJAdvice implements Advice, MethodInterceptor {

    private JoinPoint joinPoint;

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Object retValue = invocation.procccd();
        this.joinPoint = invocation;
        this.afterReturning(retValue, invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        return retValue;
    }

    public AfterReunrningJAdviceInterceptor(Method aspectMethod, Object aspectObject) {
        super(aspectMethod, aspectObject);
    }

    private void afterReturning(Object retValue, Method method, Object[] arguments, Object aThis) throws Throwable {
        super.invokeAdviceMethod(this.joinPoint, retValue, null);
    }

}
